package com.smartleanx.module.hrm.controller.admin.pay;

import com.alibaba.fastjson2.JSONObject;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.security.core.util.SecurityFrameworkUtils;
import com.smartleanx.module.hrm.dal.dataobject.esign.ContractOrder;
import com.smartleanx.module.hrm.service.esign.service.ContractPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author guo
 */
@RestController
@RequestMapping("/hrm/pay")
public class PayController {


    @Autowired
    private ContractPackageService contractPackageService;


    @GetMapping("/generationOrder")
    public CommonResult<Object> generationOrder(@RequestParam(value = "packageId", required = false) Integer packageId,
                                                @RequestParam("orderSn") String orderSn,
                                                @RequestParam(value = "payNum", required = false) Integer payNum) {
        Integer loginId = SecurityFrameworkUtils.getLoginUserId().intValue();
        ContractOrder contractOrder = contractPackageService.generationOrder(packageId, orderSn, loginId, payNum);
        return CommonResult.success(contractOrder);
    }


    @GetMapping("/orderPay")
    public CommonResult<Object> pay(@RequestParam("payType") Integer payType,
                                    @RequestParam("orderSn") String orderSn) {
        Integer loginId = SecurityFrameworkUtils.getLoginUserId().intValue();

        String payUrl = contractPackageService.pay(payType, orderSn, loginId);
        return CommonResult.success(payUrl);

    }


    @GetMapping("/packageBySelect")
    public CommonResult<Object> bySelect() {
        List<JSONObject> jsonObjectList = contractPackageService.bySelect();
        return CommonResult.success(jsonObjectList);
    }


    @GetMapping("/selectOneByContract")
    public CommonResult<Object> selectOneByContract() {
        return CommonResult.success(contractPackageService.selectOneByContract());
    }

    @GetMapping("/cancelPay")
    public CommonResult<Object> cancelPay(@RequestParam("orderSn") String orderSn) {
        return CommonResult.success(contractPackageService.cancelPay(orderSn));
    }


}
